using System;

namespace Game.Network {
    public static class TCPPacketHandlers {
        private static PacketHandler[] m_handlers;

        static TCPPacketHandlers () {
            m_handlers = new PacketHandler[0x100];

            Register (0x01, 0, new OnPacketReceive (OnLogin));
        }

        public static void Register( int packetId, int length, OnPacketReceive onReceive){
            m_handlers [packetId] = new PacketHandler (packetId, length, onReceive);
        }

        public static PacketHandler GetHandler( int packetId){
            return m_handlers [packetId];
        }

        public static void Empty(PacketReader reader){
        }

        public static void OnLogin(PacketReader reader){
            string udp_hostname = reader.ReadAsciiPString ();
            int udp_port = (int)reader.ReadUInt16 ();
            int tps = (int)reader.ReadByte ();

            if (tps == 0) {
                Client.UDPConnect (udp_hostname, udp_port, tps);
            } else {
                Client.UDPConnect (udp_hostname, udp_port);
            }
        }
    }
}

